<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .title{
      width: 80px;
      text-align: right;
    }
    .title::after{
      content: "： ";
    }
    .flex{
      display: flex;
      align-items: center;
      margin: 10px;
    }
    span{
      cursor: pointer;
    }
    .content{
      width: 280px;
      border: 1px solid #ccc;
      margin: 100px;
    }
    .info{
      padding: 10px;
      display: flex;
      justify-content: space-between;
    }
  </style>
</head>
<body>
  <div id="app">
    {{backName}}
    <div class="content">
      <div class="info">
        <div>基本信息</div>
        <div>
          <template v-if="isEdit">
            <button @click="isEdit = false">确定</button>
            <button @click = 'cancel'>取消</button>
          </template>
          <button @click="edit" v-else>编辑</button>
        </div>
      </div>
      <ul>
        <li class="flex">
          <div class="title">姓名</div>
          <div>
            <div v-if="isEdit">
              <input type="text" v-model="info.name">
            </div>
            <span v-else>{{info.name}}</span>
          </div>
        </li>
        <li class="flex">
          <div class="title">年龄</div>
          <div>
            <div v-if="isEdit">
              <input type="text" v-model="info.age">
            </div>
            <span v-else>{{info.age}}</span>
          </div>
        </li>
        <li class="flex">
          <div class="title">性别</div>
          <div>
            <div v-if="isEdit">
              <input type="text" v-model="info.gender">
            </div>
            <span v-else>{{info.gender}}</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
  new Vue({
    el:'#app',
    data() {
      return {
        isEdit:false,
        info:{
          name:'张三',
          age:18,
          gender:'男'
        },
        backName:''
      }
    },
    methods:{
      edit(){
        this.isEdit = true
        this.backName = Object.assign({},this.info)
      },
      cancel(){
        this.info = this.backName
        this.isEdit = false
      }
    }
  })
</script>
</html>